#include "Stack_Lst.h"

CStack_Lst::CStack_Lst(void)
{
    m_head = NULL;
    m_size = 0;
}

CStack_Lst::~CStack_Lst(void)
{
    Clear();
}


void CStack_Lst::Push(double data)
{
    Node* topNode = new Node();
    topNode->data = data;
    topNode->next = m_head;
    m_head = topNode;

    ++m_size;
}

bool CStack_Lst::Pop(double& data)
{
    if (NULL == m_head)
    {
        return false;
    }

    data = m_head->data;
    Node *topNode = m_head->next;
    delete m_head;
    m_head = topNode;

    --m_size;

    return true;
}

void CStack_Lst::Clear()
{
    Node* topNode = NULL;
    while(NULL != m_head)
    {
        topNode = m_head->next;
        delete m_head;
        m_head = topNode;
    }

    m_size = 0;
}


bool CStack_Lst::GetTop(double& data)
{
    if (NULL == m_head)
    {
        return false;
    }

    data = m_head->data;
    return true;
}

int CStack_Lst::GetSize()
{
    return m_size;
}

bool CStack_Lst::IsEmpty()
{
    return (NULL == m_head);
}